

local IProvider  = require("script.sdk.provider.IProvider")
local ProviderAndroid = class("ProviderAndroid", IProvider)
function ProviderAndroid:isSaveUser()
    return false
end
function ProviderAndroid:canQuickLogin()
    return false
end
function ProviderAndroid:callStaticMethod(methodName,args)
    local javaClassName = "org/cocos2dx/lua/AllInOneSdk"
    local javaMethodName = "callSdkMethod"
    local params = "lua#java"
    if args then
        
        for i, v in pairs(args) do
            local t = type(v)
            if t ~= "function" then
                params=params.."#"..i.."#"..v 
            end
        end
    end
    
   local javaParams = {
        methodName,
        params,
       function(parameters)
            parameters = string.split(parameters, "#")
            local pars = {}
            for i=1,#parameters,2 do
               pars[parameters[i]]=parameters[i+1]
            end
            dump(parameters)
            if args.listener then
                args.listener(pars)
            end
       end
   }
   
    local javaMethodSig = "(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;"
    local ok, ret = luaj.callStaticMethod(javaClassName, javaMethodName, javaParams,javaMethodSig)
    if ok then
        return ret
    elseif ret == -1 then
        printf("不支持的参数类型或返回值类型 (%s)",methodName)
    elseif ret == -2 then
        printf("无效的签名 (%s)",methodName)
    elseif ret == -3 then
        printf("没有找到指定的方法 (%s)",methodName)
    elseif ret == -4 then
        printf("Java 方法执行时抛出了异常 (%s)",methodName)
    elseif ret == -5 then
        printf("Java 虚拟机出错 (%s)",methodName)
    elseif ret == -6 then
        printf("Java 虚拟机出错 (%s)",methodName)
    else
        printf("未知错误 ret=%s (%s)",ret,methodName)
    end
    return "false"
end
return ProviderAndroid
